package com.sky.controller.user;

import com.sky.dto.UserLoginDTO;
import com.sky.pojo.User;
import com.sky.result.Result;
import com.sky.service.user.UserService;
import com.sky.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/user")
@Api(tags = "用户相关接口")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){

        UserLoginVO login = userService.login(userLoginDTO);
        return Result.success(login);
    }

    //保留用户信息
    @PostMapping
    @CachePut(value = "userCarche",key = "#user.id")
    public User save(@RequestBody User user){
        userService.save(user);
        return user;
    }
}
